//
//  WLSTabBarController.swift
//  1-微博
//
//  Created by 王隆善 on 16/7/28.
//  Copyright © 2016年 王隆善. All rights reserved.
//

import UIKit

class WLSTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        addChildViewController()
        
        //因为默认的tabBar是不会留出空间来的,因此需要自定义tabBar来加入中间的按钮用于点击
        
        //运行时:运行的时候,对象可以动态的调用 setValue forKey这个方法可以动态的给属性赋值
        
        let wlsTab = WLSTabBar()
        wlsTab.tintColor = UIColor.orangeColor()
        setValue(wlsTab, forKey: "tabBar")
        
    }
    
    
    
    func addChildViewController() {
        
        addChildViewController(WLSHomeViewController(), imageName: "tabbar_home", titleName: "首页")
        addChildViewController(WLSMessageViewController(), imageName: "tabbar_message_center", titleName: "信息")
        addChildViewController(WLSFindViewController(), imageName: "tabbar_discover", titleName: "发现")
        addChildViewController(WLSSettingViewController(), imageName: "tabbar_profile", titleName: "设置")
    }
    
    
    //添加子控制器
    func addChildViewController(childController: UIViewController,imageName: String,titleName: String) {
        
        //1,设置图片
        childController.tabBarItem.image = UIImage(named: imageName)
        
        //2,设置选中的图片
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_highlighted")
        
        //3,设置渲染方式
        tabBar.tintColor = UIColor.orangeColor()
        
        //4,设置nav标题
        childController.title = titleName
        
        //5,把自控制添加到nav
        let nav = UINavigationController(rootViewController: childController)
        
        //6,添加子控制器
        addChildViewController(nav)
        
    }

    

}
